/**
 * Created by fangshufeng on 2018/3/25.
 */

import  React from 'react'
import {ProductList, ProductDetail} from '../../components';
import {bindActionCreators} from 'redux';
import * as productAction from  '../../actions/product'
import { connect } from 'react-redux'
import { Redirect  } from 'react-router-dom'

class ProductListApp extends React.Component {
    componentDidMount() {
        // console.log(productAction);
    }
    render() {
        let {action1, action2, name, rightViewAction, isLogin,logout} = this.props
        if (isLogin) {
            return <div >
                <button onClick={logout}>退出登录</button>
                <ProductList
                    title={name}
                    action1={() => action1('w')}
                    action2={action2}/>
                <ProductDetail
                    rightViewDid={() => rightViewAction({'name': '来自另一个view的改变'})}/>

            </div>
        }else  {
            return <Redirect to='/'></Redirect>
        }
    }
}

const mapStateToProps = (state) => state.name;

const mapDispatchToProps = (dispatch) => {
    return {
        action1: bindActionCreators(productAction.action1, dispatch),
        action2: bindActionCreators(productAction.action2, dispatch),
        rightViewAction: bindActionCreators(productAction.rightViewAction, dispatch),
        logout: bindActionCreators(productAction.logout, dispatch)
    }
};

export default  connect(mapStateToProps, mapDispatchToProps)(ProductListApp);